package com.hjduan.spring.cloud.hystrix;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * Ribbon 做负载客户端负载均衡
 * Hystrix做断路器
 */
@EnableEurekaClient
@SpringBootApplication
@EnableHystrix
//次注解是用来访问hystrix的。
@EnableHystrixDashboard
public class HystrixApplicationConfiguration {

    public static void main(String[] args) {
        new SpringApplication(HystrixApplicationConfiguration.class).run(args);
    }

    /**
     * @ LoadBalanced注册表明，这个restRemplate是负载均衡的。
     * @return
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return  new  RestTemplate();
    }

}
